// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

public sealed partial class ApiKeyFiltersAggregation
{
	/// <summary>
	/// <para>
	/// Collection of queries from which to build buckets.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("filters")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyQuery>? Filters { get; set; }

	/// <summary>
	/// <para>
	/// By default, the named filters aggregation returns the buckets as an object.
	/// Set to <c>false</c> to return the buckets as an array of objects.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("keyed")]
	public bool? Keyed { get; set; }

	/// <summary>
	/// <para>
	/// Set to <c>true</c> to add a bucket to the response which will contain all documents that do not match any of the given filters.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("other_bucket")]
	public bool? OtherBucket { get; set; }

	/// <summary>
	/// <para>
	/// The key with which the other bucket is returned.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("other_bucket_key")]
	public string? OtherBucketKey { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyAggregation(ApiKeyFiltersAggregation apiKeyFiltersAggregation) => Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyAggregation.Filters(apiKeyFiltersAggregation);
}

public sealed partial class ApiKeyFiltersAggregationDescriptor<TDocument> : SerializableDescriptor<ApiKeyFiltersAggregationDescriptor<TDocument>>
{
	internal ApiKeyFiltersAggregationDescriptor(Action<ApiKeyFiltersAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public ApiKeyFiltersAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyQuery>? FiltersValue { get; set; }
	private bool? KeyedValue { get; set; }
	private bool? OtherBucketValue { get; set; }
	private string? OtherBucketKeyValue { get; set; }

	/// <summary>
	/// <para>
	/// Collection of queries from which to build buckets.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor<TDocument> Filters(Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyQuery>? filters)
	{
		FiltersValue = filters;
		return Self;
	}

	/// <summary>
	/// <para>
	/// By default, the named filters aggregation returns the buckets as an object.
	/// Set to <c>false</c> to return the buckets as an array of objects.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor<TDocument> Keyed(bool? keyed = true)
	{
		KeyedValue = keyed;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Set to <c>true</c> to add a bucket to the response which will contain all documents that do not match any of the given filters.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor<TDocument> OtherBucket(bool? otherBucket = true)
	{
		OtherBucketValue = otherBucket;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The key with which the other bucket is returned.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor<TDocument> OtherBucketKey(string? otherBucketKey)
	{
		OtherBucketKeyValue = otherBucketKey;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FiltersValue is not null)
		{
			writer.WritePropertyName("filters");
			JsonSerializer.Serialize(writer, FiltersValue, options);
		}

		if (KeyedValue.HasValue)
		{
			writer.WritePropertyName("keyed");
			writer.WriteBooleanValue(KeyedValue.Value);
		}

		if (OtherBucketValue.HasValue)
		{
			writer.WritePropertyName("other_bucket");
			writer.WriteBooleanValue(OtherBucketValue.Value);
		}

		if (!string.IsNullOrEmpty(OtherBucketKeyValue))
		{
			writer.WritePropertyName("other_bucket_key");
			writer.WriteStringValue(OtherBucketKeyValue);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class ApiKeyFiltersAggregationDescriptor : SerializableDescriptor<ApiKeyFiltersAggregationDescriptor>
{
	internal ApiKeyFiltersAggregationDescriptor(Action<ApiKeyFiltersAggregationDescriptor> configure) => configure.Invoke(this);

	public ApiKeyFiltersAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyQuery>? FiltersValue { get; set; }
	private bool? KeyedValue { get; set; }
	private bool? OtherBucketValue { get; set; }
	private string? OtherBucketKeyValue { get; set; }

	/// <summary>
	/// <para>
	/// Collection of queries from which to build buckets.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor Filters(Elastic.Clients.Elasticsearch.Serverless.Aggregations.Buckets<Elastic.Clients.Elasticsearch.Serverless.Security.ApiKeyQuery>? filters)
	{
		FiltersValue = filters;
		return Self;
	}

	/// <summary>
	/// <para>
	/// By default, the named filters aggregation returns the buckets as an object.
	/// Set to <c>false</c> to return the buckets as an array of objects.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor Keyed(bool? keyed = true)
	{
		KeyedValue = keyed;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Set to <c>true</c> to add a bucket to the response which will contain all documents that do not match any of the given filters.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor OtherBucket(bool? otherBucket = true)
	{
		OtherBucketValue = otherBucket;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The key with which the other bucket is returned.
	/// </para>
	/// </summary>
	public ApiKeyFiltersAggregationDescriptor OtherBucketKey(string? otherBucketKey)
	{
		OtherBucketKeyValue = otherBucketKey;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FiltersValue is not null)
		{
			writer.WritePropertyName("filters");
			JsonSerializer.Serialize(writer, FiltersValue, options);
		}

		if (KeyedValue.HasValue)
		{
			writer.WritePropertyName("keyed");
			writer.WriteBooleanValue(KeyedValue.Value);
		}

		if (OtherBucketValue.HasValue)
		{
			writer.WritePropertyName("other_bucket");
			writer.WriteBooleanValue(OtherBucketValue.Value);
		}

		if (!string.IsNullOrEmpty(OtherBucketKeyValue))
		{
			writer.WritePropertyName("other_bucket_key");
			writer.WriteStringValue(OtherBucketKeyValue);
		}

		writer.WriteEndObject();
	}
}